package com.aidex.system.controller;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.system.domain.RiskGoodsNameKeySuggest;
import com.aidex.system.domain.vo.SuggestApply;
import com.aidex.system.service.RiskGoodsNameKeySuggestService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 优化建议信息Controller
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-10-14
 */
@RestController
@RequestMapping("/system/riskGoodsNameKeySuggest")
public class RiskGoodsNameKeySuggestController extends BaseController
{
    @Autowired
    private RiskGoodsNameKeySuggestService riskGoodsNameKeySuggestService;

    /**
     * 查询优化建议信息列表
     */
    @GetMapping("/count")
    public R<Map<String, Integer>> count() {
        RiskGoodsNameKeySuggest suggest = new RiskGoodsNameKeySuggest();
        suggest.setStatus(0);
        List<RiskGoodsNameKeySuggest> list = riskGoodsNameKeySuggestService.findList(suggest);
        Integer a = 0, b = 0, c = 0;
        for (RiskGoodsNameKeySuggest riskGoodsNameKeySuggest : list) {
            if (riskGoodsNameKeySuggest.getType() == 1) {
                a++;
            } else if (riskGoodsNameKeySuggest.getType() == 2) {
                b++;
            } else {
                c++;
            }
        }
        Map<String, Integer> res = new HashMap<>();
        res.put("a", a);
        res.put("b", b);
        res.put("c", c);
        return R.data(res);
    }

    /**
     * 查询优化建议信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:list')")
    @GetMapping("/list")
    public R<PageInfo> list(RiskGoodsNameKeySuggest riskGoodsNameKeySuggest, HttpServletRequest request, HttpServletResponse response)
    {
        riskGoodsNameKeySuggest.setPage(new PageDomain(request, response));
        return R.data(riskGoodsNameKeySuggestService.findPage(riskGoodsNameKeySuggest));
    }

    /**
     * 获取优化建议信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:query')")
    @GetMapping(value = "/{id}")
    public R<RiskGoodsNameKeySuggest> detail(@PathVariable("id") String id)
    {
        return R.data(riskGoodsNameKeySuggestService.get(id));
    }

    /**
     * 新增优化建议信息
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:add')")
    @Log(title = "优化建议信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  RiskGoodsNameKeySuggest riskGoodsNameKeySuggest)
    {
        return R.status(riskGoodsNameKeySuggestService.save(riskGoodsNameKeySuggest));
    }

    /**
     * 修改优化建议信息
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:edit')")
    @Log(title = "优化建议信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated RiskGoodsNameKeySuggest riskGoodsNameKeySuggest)
    {
        return R.status(riskGoodsNameKeySuggestService.save(riskGoodsNameKeySuggest));
    }

    /**
     * 删除优化建议信息
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:remove')")
    @Log(title = "优化建议信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(riskGoodsNameKeySuggestService.deleteRiskGoodsNameKeySuggestByIds(ids));
    }

    /**
     * 导出优化建议信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:riskGoodsNameKeySuggest:export')")
    @Log(title = "优化建议信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(RiskGoodsNameKeySuggest riskGoodsNameKeySuggest)
    {
        List<RiskGoodsNameKeySuggest> list = riskGoodsNameKeySuggestService.findList(riskGoodsNameKeySuggest);
        ExcelUtil<RiskGoodsNameKeySuggest> util = new ExcelUtil<RiskGoodsNameKeySuggest>(RiskGoodsNameKeySuggest.class);
        return util.exportExcel(list, "riskGoodsNameKeySuggest");
    }

    /**
     * 审核货品清单
     * @param apply
     * @return
     */
    @PostMapping("apply")
    @Log(title = "审核优化建议信息", businessType = BusinessType.UPDATE)
    public R apply(@RequestBody SuggestApply apply) {
        return R.status(riskGoodsNameKeySuggestService.apply(apply));
    }

    /**
     * 审核货品清单
     * @param apply
     * @return
     */
    @PostMapping("confirm")
    @Log(title = "确认优化建议信息", businessType = BusinessType.UPDATE)
    public R confirm(@RequestBody SuggestApply apply) {
        return R.status(riskGoodsNameKeySuggestService.confirm(apply));
    }

}
